/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fir;

/**
 *
 * @author zhangyucen
 */
public class Computer {
    int row, line;
    ChessLine judge;
    int power;
    int player1Lines[][];
    int player2Lines[][];
    public Computer(ChessLine judge) {
        this.judge = judge;
        player1Lines = new int[15][15];
        player2Lines = new int[15][15];
        power = 3;
    }

    private void Count() {
        int i, j, k;
        for (i = 0; i < 15; i++) {
            for (j = 0; j < 15; j++) {
                player1Lines[i][j] = 0;
                player2Lines[i][j] = 0;
                if (judge.chess.point[i][j] == 0) {
                    for (k = 0; k < 572; k++) {
                        if (judge.chess.tableplayer1[k][i][j]) {
                            switch (judge.chessLine[k][0]) {
                                case 1:
                                    player1Lines[i][j] += 30*power;
                                    break;
                                case 2:
                                    player1Lines[i][j] += 120*power;
                                    break;
                                case 3:
                                    player1Lines[i][j] += 400*power;
                                    break;
                                case 4:
                                    player1Lines[i][j] += 1000*power;
                                    break;
                            }
                        }
                       if (judge.chess.tableplayer2[k][i][j]) {
                            switch (judge.chessLine[k][1]) {
                                case 1:
                                    player2Lines[i][j] += 90;
                                    break;
                                case 2:
                                    player2Lines[i][j] += 360;
                                    break;
                                case 3:
                                    player2Lines[i][j] += 1500;
                                    break;
                                case 4:
                                    player2Lines[i][j] += 5000;
                                    break;
                            }
                        }
                    }
                }
            }
        }
    }

    public void location() {
        int lines1Max = 0, lines2Max = 0;
        int l1Max_i = 0, l1Max_j = 0;
        int l2Max_i = 0, l2Max_j = 0;
        Count();
        for (int i = 0; i < 15; i ++) {
            for (int j = 0; j < 15; j++) {
                if (judge.chess.point[i][j] == 0) {
                    if (player1Lines[i][j] > lines1Max) {
                        lines1Max = player1Lines[i][j];
                        l1Max_i = i;
                        l1Max_j = j;
                    }
                    if (player2Lines[i][j] > lines2Max) {
                        lines2Max = player2Lines[i][j];
                        l2Max_i = i;
                        l2Max_j = j;
                    }
                }
            }
        }
        if (lines2Max > lines1Max) {
            row = l2Max_i;
            line = l2Max_j;
        } else {
            row = l1Max_i;
            line = l1Max_j;
        }
    }
}
